package sseGameApps.controller.mdkbr.main;

import java.util.HashMap;
import java.util.Map;

import org.slim3.controller.Navigation;

import sseGameApps.controller.JsonController;
import sseGameApps.model.mdkbr.MdKanji;
import sseGameApps.service.mdkbr.MdKanjiService;

public class MdSummonKanjiController extends JsonController {

    private MdKanjiService serviceMdKanji = new MdKanjiService();

    @Override
    public Navigation run() throws Exception {
        Map<String, String> data = new HashMap<String, String>();

        if ("".equals(asString("summonTxt")) || "".equals(asString("userId"))){
            data.put("summonedTxt", "");
            data.put("barPoint", "");
            data.put("attackPoint", "");
            data.put("kanjiType", "");
            this.toJson(data);
            return null;
        }

        MdKanji mdKanji = serviceMdKanji.registKanji(asString("summonTxt"), asString("userId"));

        if (mdKanji == null){
            data.put("summonedTxt", "");
            data.put("barPoint", "");
            data.put("attackPoint", "");
            data.put("kanjiType", "");
            this.toJson(data);
        }else{
            data.put("summonedTxt", mdKanji.getMojiText());
            data.put("barPoint", mdKanji.getBarPoint().toString());
            data.put("attackPoint", mdKanji.getAttackPoint().toString());
            data.put("kanjiType", mdKanji.getKanjiTypeText());
            this.toJson(data);
        }
        return null;
    }
}
